package com.yuninglong.server;

import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yuninglong
 */

@Log4j2
@RestController
@RequestMapping("config")
@RefreshScope //启动类上面加了无效，需要在这里加上，下面的@Value才会生效
public class ConfigController {

    @Autowired
    private ConfigProperties configProperties;

    @Value(value = "${useLocalCache:0}")
    private String useLocalCache;

    @Autowired
    private NacosConfig nacosConfig;

    @GetMapping(value = "/get")
    public String get() {
        String info = useLocalCache + "=====" + nacosConfig.getUseLocalCache()
                + "----" + configProperties.getToken() + "---" + nacosConfig.getToken() + "===";
        log.info("info-------------"+info);
        return info;
    }
}
